package com.bookbuf.biz.app;

import android.app.Activity;
import android.databinding.DataBindingUtil;
import android.os.Bundle;

import com.bookbuf.biz.R;
import com.bookbuf.biz.app.dagger2.component.DaggerExamDetailActivityComponent;
import com.bookbuf.biz.app.dagger2.module.ExamDetailActivityModule;
import com.bookbuf.biz.app.vm.ExamViewModel;
import com.bookbuf.biz.databinding.ItemExamBinding;
import com.bookbuf.library.domain.User;
import com.bookbuf.module.manager.StubManager;
import com.bookbuf.module.stub.impl.BizProxyStub;

import javax.inject.Inject;

public class ExamDetailActivity extends Activity {

    @Inject
    public ExamViewModel vm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setUpComponent();
        ItemExamBinding binding =
                DataBindingUtil.setContentView(this, R.layout.item_exam);
        binding.setVm(vm);

        // FIXME: 2016/12/29 因为引用到了外部依赖，所以需要使用stub
        BizProxyStub stub = StubManager.getManager().obtainPrivate();
        if (stub != null) {
            User user = stub.getDependence().injectUser();
            binding.setUser(user);
        }


    }

    private void setUpComponent() {
        DaggerExamDetailActivityComponent
                .builder()
                .examDetailActivityModule(
                        new ExamDetailActivityModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // no need release component.
    }
}
